package com.lucas.vistart.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.lucas.vistart.R;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class register2 extends AppCompatActivity {

    private ImageButton setGender;
    private ImageButton setBirth;
    ArrayList<String> genderList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_info2);
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }
        setGender = findViewById(R.id.setGenderBtn);
        setBirth = findViewById(R.id.setBirthBtn);

        genderList.add("保密");
        genderList.add("男");
        genderList.add("女");

        TextView tv1 = findViewById(R.id.tv1);
        TextView tv2 = findViewById(R.id.tv2);

        //时间选择器
        TimePickerView bdPicker = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                tv2.setText(df.format(date));
            }
        }).build();

        //条件选择器
        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3 ,View v) {
                //返回的分别是三个级别的选中位置
                String tx = genderList.get(options1);
                tv1.setText(tx);
            }
        }).build();
        pvOptions.setPicker(genderList);

        setGender.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pvOptions.show();
            }
        });


        setBirth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bdPicker.show();
            }
        });
    }
}